module.exports = {
  getAllIndexFlag () {
    if (!this.marketInfo) {
      return {}
    }
    return {
      isIndexInNewHighTrend: this.isIndexInNewHighTrend(),
      isIndexInNewLowTrend: this.isIndexInNewLowTrend(),
      isIndexCloseNewHigh: this.isIndexCloseNewHigh(),
      isIndexCloseNewLow: this.isIndexCloseNewLow(),
      isIndexCloseNowNewHigh: this.isIndexCloseNowNewHigh(),
      isIndexCloseNowNewLow: this.isIndexCloseNowNewLow()
    }
  },
  // 新高趋势
  isIndexInNewHighTrend () {
    let maxType = 'highIndex'
    if (this.marketFlagInfo.isMarketMiniGoodUp) {
      maxType = 'maxCloseIndex'
    }
    const countModel4h = this.marketInfo.countModel4h || {}
    let macd4h = this.analysisInfo4h.macdUpDays > 2
    if (
      (this.marketInfo.ema4hGood && (countModel4h.countMacdUp < (0.8 * this.marketInfo.asCount))) ||
      !this.marketInfo.macd1hGood
    ) {
      macd4h = this.analysisInfo4h.macdUpDays > 8
    }
    if (
      this.analysisInfo4h.isDuo &&
      this.analysisInfo1h.isLongDuo &&
      (
        this.analysisInfo1h.kdjDiff > 0 ||
        (this.analysisInfo1h.kdjDownDays === 1 && this.tradeTime15mCycle !== 4) ||
        (this.analysisInfo1h.kdjDownDays === 1 && this.marketFlagInfo.ifMarket4hMacdEmaAllGood && this.marketFlagInfo.ifMarket1hMacdEmaHasGood && !this.marketFlagInfo.ifMarket1hMacdEmaHasBad) ||
        (this.analysisInfo1h.macd > 0 && this.analysisInfo1h.isMacdIncrease && this.marketFlagInfo.isMarketLittleGoodUp)
      ) &&
      this.analysisInfo4h.highLowInfo20[maxType] <= 1 &&
      macd4h &&
      this.analysisInfo1h.highLowInfo20[maxType] <= (this.marketFlagInfo.isMarketMiniGoodUp ? 3 : 2) &&
      (
        this.analysisInfo1h.macdUpDays !== 1 ||
        (this.marketInfo.macd1hGood && this.marketInfo.ema1hGood && this.marketInfo.macd4hGood && this.marketInfo.ema4hGood)
      ) &&
      // 保持时间久的更有潜力
      (
        this.analysisInfo1h.ema5W10A20Days >= 20 ||
        (
          this.analysisInfo1h.ema5W10A20Days >= 12 &&
          this.analysisInfo1h.macdUpDays >= 16
        ) ||
        (
          (this.analysisInfo1h.ema5W10A20Days >= 8 && this.analysisInfo1h.macdUpDays >= 8) &&
          this.analysisInfo1h.kdjUpDays >= 12
        )
      ) &&
      // 保持时间久的更有潜力
      !(this.analysisInfo15m.ema10A20Days < 12 && this.analysisInfo1h.kdjUpDays <= 2)
    ) {
      if (
        (
          this.analysisInfo1d.isDuo &&
          this.analysisInfo1d.highLowInfo20[maxType] <= 1
        ) ||
        (!this.analysisInfo1d.hasFullData && (this.marketInfo.macd1dGood || this.marketInfo.ema1dGood)) ||
        (
          (this.marketInfo.macd1dGood || this.marketInfo.ema1dGood) &&
          this.analysisInfo1d.kdjDiff > 0
        )
      ) {
        return true
      }
    }
    if (this.marketFlagInfo.ifMarket1dMacdEmaAllGood && this.marketFlagInfo.ifMarket4hMacdEmaHasGood) {
      if (this.analysisInfo1d.macdUpDays >= 20 && this.analysisInfo1d.ema5W10A20Days >= 8 && this.analysisInfo1d.kdjUpDays >= 10) {
        if (this.analysisInfo4h.macdUpDays >= 8 && this.analysisInfo4h.ema5W10A20Days >= 9 && this.analysisInfo4h.kdjDiff > 0) {
          if (this.analysisInfo1d.highLowInfo20.maxCloseIndex <= 1 && this.analysisInfo4h.highLowInfo20.maxCloseIndex <= 1) {
            if (this.analysisInfo1h.isDuo && this.analysisInfo1h.highLowInfo20.maxCloseIndex <= 1) {
              return true
            }
          }
        }
      }
      if (this.analysisInfo1d.macdUpDays >= 20 && this.analysisInfo1d.ema5W10A20Days >= 8 && this.analysisInfo1d.isKdjIncrease) {
        if (this.analysisInfo4h.macdUpDays > 4 && this.analysisInfo4h.ema5W10A20Days >= 6 && this.analysisInfo4h.kdjUpDays >= 6) {
          if (this.analysisInfo1h.macdUpDays > 24 && this.analysisInfo1h.ema5W10A20Days >= 24 && this.analysisInfo1h.ema5A10A20Days >= 4 && this.analysisInfo1h.kdjDiff > 0) {
            if (this.analysisInfo1d.highLowInfo20.maxCloseIndex <= 1 && this.analysisInfo4h.highLowInfo20.maxCloseIndex <= 1) {
              if (this.analysisInfo1h.isDuo && this.analysisInfo1h.highLowInfo20.maxCloseIndex <= 1) {
                return true
              }
            }
          }
        }
      }
      if (this.isIndexCloseNowNewHigh() && this.marketInfo.ema1hGood) {
        if (this.analysisInfo1d.isDuo && this.analysisInfo1d.macdUpDays >= 12) {
          if (this.analysisInfo4h.isDuo && this.analysisInfo4h.kdjUpDays >= 6 && this.analysisInfo4h.macdUpDays >= 4) {
            if (this.analysisInfo1h.macdUpDays > 36 && this.analysisInfo1h.ema5W10A20Days >= 16 && this.analysisInfo1h.isDuo) {
              return true
            }
          }
        }
      }
    }
    return false
  },
  isIndexInNewLowTrend () {
    let minType = 'lowIndex'
    if (this.marketFlagInfo.isMarketMiniBadDown) {
      minType = 'minCloseIndex'
    }
    const countModel4h = this.marketInfo.countModel4h || {}
    let macd4h = this.analysisInfo4h.macdDownDays > 2
    if (
      (this.marketInfo.ema4hBad && (countModel4h.countMacdDown < (0.8 * this.marketInfo.asCount))) ||
      !this.marketInfo.macd1hBad
    ) {
      macd4h = this.analysisInfo4h.macdDownDays > 8
    }
    if (
      this.analysisInfo4h.isKong &&
      this.analysisInfo1h.isLongKong &&
      (
        this.analysisInfo1h.kdjDiff < 0 ||
        (this.analysisInfo1h.kdjUpDays === 1 && this.tradeTime15mCycle !== 4) ||
        (this.analysisInfo1h.kdjUpDays === 1 && this.marketFlagInfo.ifMarket4hMacdEmaAllBad && this.marketFlagInfo.ifMarket1hMacdEmaHasBad && !this.marketFlagInfo.ifMarket1hMacdEmaHasGood) ||
        (this.analysisInfo1h.macd < 0 && this.analysisInfo1h.isMacdDecline && this.marketFlagInfo.isMarketLittleBadDown)
      ) &&
      this.analysisInfo4h.highLowInfo20[minType] <= 1 &&
      macd4h &&
      this.analysisInfo1h.highLowInfo20[minType] <= (this.marketFlagInfo.isMarketMiniBadDown ? 3 : 2) &&
      (
        this.analysisInfo1h.macdDownDays !== 1 ||
        (this.marketInfo.macd1hBad && this.marketInfo.ema1hBad && this.marketInfo.macd4hBad && this.marketInfo.ema4hBad)
      ) &&
      (
        this.analysisInfo1h.ema5W10B20Days >= 20 ||
        (
          this.analysisInfo1h.ema5W10B20Days >= 12 &&
          this.analysisInfo1h.macdDownDays >= 16
        ) ||
        (
          (this.analysisInfo1h.ema5W10B20Days >= 8 && this.analysisInfo1h.macdDownDays >= 8) &&
          this.analysisInfo1h.kdjDownDays >= 12
        )
      ) &&
      !(this.analysisInfo15m.ema10B20Days < 12 && this.analysisInfo1h.kdjDownDays <= 2)
    ) {
      if (
        (
          this.analysisInfo1d.isKong &&
          this.analysisInfo1d.highLowInfo20[minType] <= 1
        ) ||
        (!this.analysisInfo1d.hasFullData && (this.marketInfo.macd1dBad || this.marketInfo.ema1dBad)) ||
        (
          (this.marketInfo.macd1dBad || this.marketInfo.ema1dBad) &&
          this.analysisInfo1d.kdjDiff < 0
        )
      ) {
        return true
      }
    }
    if (this.marketFlagInfo.ifMarket1dMacdEmaAllBad && this.marketFlagInfo.ifMarket4hMacdEmaHasBad) {
      if (this.analysisInfo1d.macdDownDays >= 20 && this.analysisInfo1d.ema5W10B20Days >= 8 && this.analysisInfo1d.kdjDownDays >= 10) {
        if (this.analysisInfo4h.macdDownDays >= 8 && this.analysisInfo4h.ema5W10B20Days >= 9 && this.analysisInfo4h.kdjDiff < 0) {
          if (this.analysisInfo1d.highLowInfo20.minCloseIndex <= 1 && this.analysisInfo4h.highLowInfo20.minCloseIndex <= 1) {
            if (this.analysisInfo1h.isKong && this.analysisInfo1h.highLowInfo20.minCloseIndex <= 1) {
              return true
            }
          }
        }
      }
      if (this.analysisInfo1d.macdDownDays >= 20 && this.analysisInfo1d.ema5W10B20Days >= 8 && this.analysisInfo1d.isKdjDecline) {
        if (this.analysisInfo4h.macdDownDays > 4 && this.analysisInfo4h.ema5W10B20Days >= 6 && this.analysisInfo4h.kdjDownDays >= 6) {
          if (this.analysisInfo1h.macdDownDays > 24 && this.analysisInfo1h.ema5W10B20Days >= 24 && this.analysisInfo1h.ema5B10B20Days >= 4 && this.analysisInfo1h.kdjDiff < 0) {
            if (this.analysisInfo1d.highLowInfo20.minCloseIndex <= 1 && this.analysisInfo4h.highLowInfo20.minCloseIndex <= 1) {
              if (this.analysisInfo1h.isKong && this.analysisInfo1h.highLowInfo20.minCloseIndex <= 1) {
                return true
              }
            }
          }
        }
      }
      if (this.isIndexCloseNowNewLow() && this.marketInfo.ema1hBad) {
        if (this.analysisInfo1d.isKong && this.analysisInfo1d.macdDownDays >= 12) {
          if (this.analysisInfo4h.isKong && this.analysisInfo4h.kdjUpDays >= 6 && this.analysisInfo4h.macdDownDays >= 4) {
            if (this.analysisInfo1h.macdDownDays > 36 && this.analysisInfo1h.ema5W10B20Days >= 16 && this.analysisInfo1h.isKong) {
              return true
            }
          }
        }
      }
    }
    return false
  },
  isIndexCloseNewHigh () {
    if (!this.analysisInfo1d.hasFullData) {
      return false
    }
    if (this.analysisInfo1d.highLowInfo20.maxCloseIndex <= 1) {
      if (
        this.analysisInfo4h.highLowInfo20.maxCloseIndex <= 1 &&
        this.analysisInfo1h.highLowInfo20.maxCloseIndex <= 2
      ) {
        return true
      }
    }
    return false
  },
  isIndexCloseNowNewHigh () {
    if (!this.analysisInfo1d.hasFullData) {
      return false
    }
    if (this.analysisInfo1d.highLowInfo20.maxCloseIndex === 0) {
      if (
        this.analysisInfo4h.highLowInfo20.maxCloseIndex === 0 &&
        this.analysisInfo1h.highLowInfo20.maxCloseIndex <= 1
      ) {
        return true
      }
    }
    return false
  },
  isIndexCloseNewLow () {
    if (!this.analysisInfo1d.hasFullData) {
      return false
    }
    if (this.analysisInfo1d.highLowInfo20.minCloseIndex <= 1) {
      if (
        this.analysisInfo4h.highLowInfo20.minCloseIndex <= 1 &&
        this.analysisInfo1h.highLowInfo20.minCloseIndex <= 2
      ) {
        return true
      }
    }
    return false
  },
  isIndexCloseNowNewLow () {
    if (!this.analysisInfo1d.hasFullData) {
      return false
    }
    if (this.analysisInfo1d.highLowInfo20.minCloseIndex === 0) {
      if (
        this.analysisInfo4h.highLowInfo20.minCloseIndex === 0 &&
        this.analysisInfo1h.highLowInfo20.minCloseIndex <= 1
      ) {
        return true
      }
    }
    return false
  }
}
